package com.taxi.daos.mysql;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Map;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.taxi.bean.ChoferBean;
import com.taxi.daos.interfaces.ChoferDAO;
import com.taxi.util.UtilSqlConfig;

public class ChoferDAOImpl implements ChoferDAO {

	SqlMapClient sqlMapClient = UtilSqlConfig.getSqlMapInstance();
	
	 
	public int registrarchofer(ChoferBean bean) throws Exception {
		// TODO Auto-generated method stub
		try {
			sqlMapClient.insert("registrarChofer", bean);
			return 1;
		} catch (Exception e) {
			System.out.println("Error : " + e.getMessage());
			return 0;
		}		
	}

	 
	public ChoferBean codigoAutogenerado() throws Exception {
		// TODO Auto-generated method stub
		return (ChoferBean)sqlMapClient.queryForObject("obtenerAutogeneradoChofer");
	}
	 
	public ArrayList<ChoferBean> listaChofer() throws Exception {
		// TODO Auto-generated method stub
		return (ArrayList<ChoferBean>)sqlMapClient.queryForList("listarChofer");
	}
	 
	public ChoferBean listarxnombresChofer(String nombres) throws Exception {
		// TODO Auto-generated method stub
		return (ChoferBean)sqlMapClient.queryForObject("listarxnombresChofer", nombres);
	}

	 
	public void actualizarChofer(ChoferBean bean) throws Exception {
		sqlMapClient.insert("actualizarChofer", bean);		
	}

	 
	public void eliminarChofer(String codigo) throws Exception {
		sqlMapClient.insert("eliminarChofer", codigo);		
	}

	 
	public ChoferBean obtenerPlacaPorChofer(int id) throws Exception {
		// TODO Auto-generated method stub
		
		ChoferBean bean = new ChoferBean();
		try {
			 bean = (ChoferBean) sqlMapClient.queryForObject("obtenerPlacaPorChofer", id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return bean;
	}

}
